<template>
  <a-dropdown placement="bottomRight" arrow trigger="click">
    <iconfont
      name="#icon-gengduo"
      style="
        color: #1677ff;
        font-size: 18px;
        margin-left: 5px;
        outline: 0;
        cursor: pointer;
      "
    />
    <template #overlay>
      <a-menu forceSubMenuRender>
        <!-- 表格操作：更多 -->
        <a-menu-item
          @click="openRelation = true"
          v-if="data.dataType === 'file'"
        >
          <div style="position: relative; height: 24px">建立关系</div>
        </a-menu-item>
        <a-menu-item v-if="data.dataType === 'file' && data.isPersonal !== 1">
          <div style="position: relative; height: 24px; min-width: 50px">
            <div
              style="
                position: absolute;
                top: -5px;
                bottom: -5px;
                left: -12px;
                right: -12px;
              "
            >
              <!-- 分享 -->
              <button-share v-if="data.isPersonal === 0" :data="data" />
              <provide-context v-if="data.isPersonal === 1">
                <button-share :data="data"
              /></provide-context>
              <provide-context-library v-if="data.isPersonal === 2">
                <button-share :data="data"
              /></provide-context-library>
            </div>
          </div>
        </a-menu-item>
        <a-menu-item>
          <div style="position: relative; height: 24px; min-width: 50px">
            <div
              style="
                position: absolute;
                top: -5px;
                bottom: -5px;
                left: -12px;
                right: -12px;
              "
            >
              <!-- 收藏、取消收藏 -->
              <provide-context v-if="data.isPersonal !== 0">
                <button-favorite :data="data" @change="favoriteChange" />
              </provide-context>
              <button-favorite v-else :data="data" @change="favoriteChange" />
            </div>
          </div>
        </a-menu-item>
        <a-menu-item v-if="data.permissions.view && data.dataType === 'file'">
          <router-link
            v-if="data?.isPersonal === 1"
            :to="`/private/db-management-preview-personal/${data.parentId}/${data.dataId}/${data.fileId}`"
          >
            预览
          </router-link>
          <router-link
            v-if="data?.isPersonal === 2"
            :to="`/private/db-management-preview-library/${data.parentId}/${data.dataId}/${data.fileId}`"
          >
            预览
          </router-link>
          <router-link
            v-if="data?.isPersonal === 0"
            :to="`/private/db-management-preview/${data.parentId}/${data.dataId}/${data.fileId}`"
          >
            预览
          </router-link>
        </a-menu-item>

        <a-menu-item v-if="data.permissions.delete">
          <div style="position: relative; height: 24px; min-width: 50px">
            <div
              style="
                position: absolute;
                top: -5px;
                bottom: -5px;
                left: -12px;
                right: -12px;
              "
            >
              <!-- 作废 -->
              <provide-context v-if="data.isPersonal === 1">
                <button-invalid :data="data" />
              </provide-context>
              <button-invalid v-else :data="data" />
            </div>
          </div>
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
  <provide-context v-if="data.isPersonal === 1">
    <drawer-relation v-model:open="openRelation" :data="data" />
  </provide-context>
  <drawer-relation v-else v-model:open="openRelation" :data="data" />
</template>
<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import iconfont from '@/components/iconfont.vue'
import ButtonInvalid from './table-content-invalid.vue'
// import ButtonInvalid from '@/views/db-management/table-content-invalid.vue'
import ButtonShare from './table-content-share.vue'
import ButtonFavorite from './table-content-favorite-free.vue'
import DrawerRelation from '@/views/db-management/file-relation-drawer-free.vue'
import { usePermission, useDataSourceManager } from './provide-context.js'
import ProvideContext from '@/views/db-management-personal/provide-context.vue'
import ProvideContextLibrary from '@/views/db-management-library/provide-context.vue'

/**
 * 获取参数
 */
defineProps({
  data: { type: Object, required: true },
})

/**
 * 全局数据
 */
let permission = usePermission()
//
let loading = ref(false)
let openRelation = ref(false)
// 收藏后刷新
let { update } = useDataSourceManager()

function favoriteChange() {
  update()
}
</script>
<style lang="less" scoped></style>
